package org.zk.dubbo_provider.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.zk.dubbo_provider.dao.AdminBillMapper;
import org.zk.dubbo_provider.dao.TixianMapper;
import org.zk.entity.AdminBill;
import org.zk.entity.Teacher;
import org.zk.entity.Tixian;
import org.zk.service.TixianService;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 李亚婷
 * @date 2019/12/16 0016 下午 4:20
 */
@Service(timeout = 10000)
@CacheConfig(cacheNames = "tixian")
public class TixianServiceImpl implements TixianService {
    @Resource
    private TixianMapper tixianMapper;
    @Resource
    private AdminBillMapper adminBillMapper;


    /**
     * 查询所有提现记录
     * @param map
     * @return
     */
    @Override
    public PageInfo getApplyTixianPage(Map map){
        PageInfo<Tixian> pageInfo;

        int pageSize=Integer.parseInt(String.valueOf(map.get("pageSize")));
        int pageNum=Integer.parseInt(String.valueOf(map.get("pageNum")));
        PageHelper.startPage(pageNum,pageSize);
        //2.紧跟的查询就是一个分页查询-必须紧跟.后面的其他查询不会被分页，除非再次调用PageHelper.startPage
        try {
            List<Tixian> list=tixianMapper.getApplyTixian(map);
            //System.out.println("分页数据："+List);
            //3.使用PageInfo包装查询后的结果,5是连续显示的条数,结果list类型是Page<E>
             pageInfo = new PageInfo<Tixian>(list,pageSize);

        }finally {
            PageHelper.clearPage(); //清理 ThreadLocal 存储的分页参数,保证线程安全
        }
        return pageInfo;
    }

    /**
     * 查询教师提现的支付宝账号
     * @param id
     * @return
     */
    @Override
    public Teacher getTeacherZhifubao(int id) {
        return tixianMapper.getTeacherZhifubao(id);
    }



/*    public static void main(String[] args) {
      TixianServiceImpl t=new TixianServiceImpl();
      t.test(1);
    }
    public void test(int id){
        Teacher t=tixianMapper.getTeacherZhifubao(id);
        System.out.println(t.getTeacherZhifubao());
    }*/
    /**
     * 更新提现状态
     * @param id
     */
    @Override
    public void updateTixianStatusTeacher(int id,int adminid) {
        tixianMapper.updateTeacherTixianStatus(id);
        Tixian tixian = tixianMapper.getTeacherTixianById(id);
        Map<String,Object> map1 = new HashMap<>();
        System.out.println(tixian.getTeacher().getTeacherId());
        System.out.println(tixian.getTixianMoney());
        map1.put("teacherid",tixian.getTeacher().getTeacherId());
        map1.put("price",tixian.getTixianMoney());
        map1.put("adminid",adminid);
        adminBillMapper.insertTeacherBillToAdminBill(map1);
    }

    /**
     * 查询老师的提现详情
     * @param id
     * @return
     */
    @Override
    public Tixian getTeacherTixian(int id) {
        return tixianMapper.getTeacherTixian(id);
    }

    /**
     * 删除提现申请
     * @param id
     */
    @Override
    public void delTixian(int id) {
        tixianMapper.delTixian(id);
    }

    public TixianMapper getTixianMapper() {
        return tixianMapper;
    }

    public void setTixianMapper(TixianMapper tixianMapper) {
        this.tixianMapper = tixianMapper;
    }
}
